package com.envper.common.service.repair.impl;

import com.envper.common.domain.dto.RepairDto;
import com.envper.common.mapper.RepairMapper;
import com.envper.common.service.repair.RepairService;
import com.envper.common.util.IdUtils;
import com.envper.mysql.base.service.RepairBaseService;
import com.envper.mysql.domain.entity.TRepair;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
@RequiredArgsConstructor
public class RepairServiceImpl implements RepairService {
    private final RepairBaseService repairBaseService;


    @Override
    public void addRepair(RepairDto repairDto) {
        Long id = IdUtils.createId();
        TRepair tRepair = TRepair.builder()
                .id(id)
                .content(repairDto.getContent())
                .status("待解决")
                .createTime(LocalDateTime.now())
                .updateTime(LocalDateTime.now())
                .build();
        repairBaseService.save(tRepair);
    }

    @Override
    public List<RepairDto> getRepairList() {
        List<TRepair> tRepairList = repairBaseService.list();
        return RepairMapper.INSTANCE.toRepairDtoList(tRepairList);
    }
}
